package com.woniuxy.business.controller;

import com.woniuxy.business.mapper.BorrowDemandMapper;
import com.woniuxy.entity.BorrowDemand;
import com.woniuxy.utils.ResponseResult;
import com.woniuxy.utils.ResultStatus;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author shichen
 * @create 2021-11-17-21:34
 * @description 只是对 mapper 的薄封装方便后续模块的调用
 */

@RestController
public class BorrowDemandController {

    @Resource
    BorrowDemandMapper borrowDemandMapper;

    @PostMapping("/insert")
    public ResponseResult insert(@RequestBody BorrowDemand borrowDemand){
        borrowDemandMapper.insertBorrowDemand(borrowDemand);
        ResponseResult result = new ResponseResult<>();
        result.setStatus(ResultStatus.NO_PERMS);
        result.setMessage("insert ok!");
        result.setCode(200);
        return result;
    }
    @GetMapping("/select/{id}")
    public ResponseResult<BorrowDemand> select(@PathVariable("id") int id) {

        ResponseResult<BorrowDemand> result = new ResponseResult<BorrowDemand>();

        BorrowDemand borrowDemand = borrowDemandMapper.selectBorrowDemandById(id);
        if (borrowDemand != null) {
            result.setData(borrowDemand);
            result.setStatus(ResultStatus.HAVE_PERMS);
            result.setMessage("select ok!");
            result.setCode(200);
        } else {
            result.setStatus(ResultStatus.NO_PERMS);
            result.setMessage("no message!");
            result.setCode(200);
        }
        return result;
    }

}
